# Replication Package: The Demographic Erosion of Fiscal Leverage — Twin Deficits in an Aging World

## Overview
This folder contains all files needed to replicate the analysis in "The Demographic Erosion of Fiscal Leverage: Twin Deficits in an Aging World." The paper decomposes the current account into trade and non-trade components (Z₁=41.4** on non-trade residual, trade null), then shows that aging dramatically weakens fiscal transmission to the CA: the fiscal coefficient declines from 0.71 in young economies to 0.061 in aged ones (12× decline), with fiscal×OADR interaction = −2.76***.

## Requirements
- Python 3.10+
- pandas, numpy, scipy, statsmodels
- Data files in data/processed/

## Structure
- `scripts/` — Analysis scripts (run in phase order)
- `src/` — Shared modules (PanelGLS estimator, data loading, country classifications)
- `data/processed/` — Processed panel data (extensions_panel.csv)
- `output/tables/` — Generated output tables
- `paper/` — Paper manuscript and references

## Reproduction
Run scripts in numerical phase order:
```
python scripts/phase1_data_prep.py
python scripts/phase2_ca_decomposition.py
python scripts/phase3_twin_deficits.py
python scripts/phase5_reviewer_fixes.py
```

Phase 2 produces the CA decomposition tables (ca_decomposition.md). Phase 3 produces the twin deficits tables (twin_deficits.md). Phase 5 produces robustness tables (income validation, NFA creditor/debtor detail, KAOPEN robustness).

## Output Tables
- `ca_decomposition.md` — CA decomposition: trade vs non-trade residual (Table 1)
- `twin_deficits.md` — Twin deficits interactions and tercile splits (Table 2)
- `phase5_income_validation.md` — Non-trade residual vs official BOP income validation (Table A1)
- `phase5_nfa_detail.md` — NFA creditor/debtor asymmetry detail
- `phase5_nfa_creditor_robustness.md` — NFA creditor robustness: world rate control
- `phase5_kaopen_robustness.md` — KAOPEN interaction robustness with trade openness and ERS controls

## Data Sources
- UN World Population Prospects 2024
- IMF World Economic Outlook
- Penn World Table 10.01
- Chinn-Ito KAOPEN Index
- Lane & Milesi-Ferretti External Wealth of Nations
- World Bank WDI (trade balance NE.RSB.GNFS.ZS, primary income, GDP)

## Notes
- All analysis uses the expanded panel (up to 170 countries, 1990–2024)
- The `src/` modules are from the multilateral/followup project
- Phase 4 (KAOPEN prediction) and FH tables belong to the companion paper ("Why Feldstein-Horioka Correlations Vary")
